feat: interactive force-directed knowledge graph viewer (#118)#238
Merged
Conversation
Upgrade `llmwiki/graph.py`'s HTML template into a full interactive viewer per Karpathy's spec. New capabilities on top of the existing vis-network force layout: - Live search input filters nodes by label/id (dims non-matches) - Click a node to open its wiki page in a new tab (wiki/entities/Foo.md → entities/Foo.html rewrite) - Stats overlay panel: pages, edges, orphans, avg connections, top-5 hubs - Orphan highlighting: nodes with zero inbound links get a red 3 px border - Cluster-by-type toggle (sources / entities / concepts / syntheses) - Dark/light theme toggle that mirrors the site's localStorage key — both palettes drive the same CSS custom properties - Offline fallback notice if vis-network CDN fails to load Site integration: new `copy_to_site()` helper wires the viewer into `build_site()` so `python3 -m llmwiki build` writes `site/graph.html` and the nav gains a "Graph" link between "Compare" and "Changelog". XSS-defensive: stats panel uses `escapeHtml()` on user labels and `write_html()` escapes literal `</script>` in the embedded JSON. 25 tests covering the graph builder edge cases, every interactive feature, JSON injection, closing-tag escape, `copy_to_site()` behaviour, site-nav integration, and a 25 kB template size budget.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #118. Upgrades
llmwiki/graph.py's static HTML to a full interactive viewer that matches Karpathy's "Obsidian-graph quality" bar — search, click-to-navigate, dark/light theme, orphan highlight, cluster toggle, stats panel.New capabilities
#search-inputin headerclickhandler#stats-overlay(bottom-right)isOrphanbranch in node builder#cluster-toggle, usesnetwork.cluster()#theme-toggle+ CSS[data-theme]palettes#offline-notice+typeof vis === 'undefined'guard#legendtop-rightSite integration
copy_to_site()helper:build_site()now writessite/graph.htmlon every build.python3 -m llmwiki build→wrote site/graph.html (interactive graph viewer).XSS hygiene
escapeHtml().write_html()escapes literal</script>inside the embedded JSON before injection, so a wiki page titled</script>can't break out of the payload.Test plan
tests/test_graph_viewer.pypass (graph-builder edge cases, every interactive feature, JSON injection,</script>escape,copy_to_site(), site-nav integration, 25 kB template budget)python3 -m llmwiki buildemitssite/graph.html+ nav link### AddedOut of scope (tracked separately)
Checklist